package org.finesys.chat.core.base.document.loader;

import org.finesys.chat.core.base.document.Document;
import org.finesys.chat.core.base.document.source.URLSource;
import org.finesys.chat.core.base.document.parser.DocumentParser;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * 根据URL解析文档
 */
public class UrlDocumentLoader {

    public static Document load(URL url, DocumentParser documentParser) {
        return DocumentLoader.load(URLSource.from(url), documentParser);
    }

    public static Document load(String url, DocumentParser documentParser) {
        return load(createURL(url), documentParser);
    }

    public static URL createURL(String url) {
        try {
            return new URL(url);
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }

    }
}
